package com.pan.structual.facade.component;

import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;

public class ShapeCreate {

    private String shape = "circle";

    public void setShape(String shape) {
        this.shape = shape;
    }

    private Color color = Color.RED;
    public void setColor(Color color){
        this.color = color;
    }

    private Color backgroundColor = Color.WHITE;

    public void setBackgroundColor(Color backgroundColor) {
        this.backgroundColor = backgroundColor;
    }

    public BufferedImage getShapeImage(){

        // 创建一个BufferedImage对象
        int width = 150;
        int height = 150;
        BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

        // 在BufferedImage上绘制图形
        Graphics2D g2d = bufferedImage.createGraphics();
        g2d.setColor(backgroundColor);
        g2d.fillRect(0,0,150,150);

        g2d.setColor(color);
        if (shape.equals("square")){
            g2d.fillRect(50, 50, 50, 50);
        } else if (shape.equals("circle")) {
            g2d.fillOval(50,50,50,50);
        } else if (shape.equals("rectangle")) {
            g2d.fillRect(25,50,100,50);
        } else  {
            throw  new RuntimeException("不存在图形");
        }
        g2d.dispose();
        return bufferedImage;
    }
}
